home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 544 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: tools.bbnplanet.com!not-for-mail
  2. From: barmar@tools.bbnplanet.com (Barry Margolin)
  3. Newsgroups: comp.infosystems.www.misc,comp.lang.misc,comp.lang.perl.misc,comp.lang.c
  4. Subject: Re: Perl vs. C (was Re: Unix or NT? Get a Mac!)
  5. Date: 6 Jan 1996 16:20:57 -0500
  6. Organization: BBN Planet Corp., Cambridge, MA
  7. Message-ID: <4cmp3p$5ln@tools.bbnplanet.com>
  8. References: <4cgfp9$pje@hecate.umd.edu> <4cji0c$21e@hecate.umd.edu> <4ckm4l$4vu@tools.bbnplanet.com> <4cksih$goq@hecate.umd.edu>
  9. NNTP-Posting-Host: tools.bbnplanet.com
  10.  
  11. In article <4cksih$goq@hecate.umd.edu>, Ram Samudrala <me@ram.org> wrote:
  12. >In all my experience with programming contests, I've never had to
  13. >resort to any complex functions or features of a specific language
  14. >(which C has a few of, but I think it just gets you into trouble)---in
  15. >fact, I prefer using standard Pascal than anything else.  I prefer the
  16. >Occam's razor approach, and I really don't see how using Perl could
  17. >make it "far too easy".
  18.  
  19. Well, a couple of years ago I wanted to add some features and bug fixes to
  20. a program at my former employer.  The program was our internal variant of
  21. "finger"; it looked people up in our employee file, allowing you to specify
  22. first name, last name, Unix username, nicknames, or even substrings.  The
  23. program was about 2,000 lines of C, which included some home-grown
  24. libraries for parsing the data files (just flat files somewhat like
  25. /etc/passwd format) and memory management; it was written by a Lisp
  26. programmer, so it did lots of stuff using linked lists and
  27. dynamically-growing arrays.  And even with those memory management
  28. routines, the program had some hard-coded limitations -- if a name was
  29. ambiguous, only 10 matching names would be displayed.
  30.  
  31. In a weekend I rewrote the program into about 500 lines of Perl.  All the
  32. parsing and memory management routines were replaced with Perl's built-in
  33. arrays and the split() function.  One of the bugs I was fixing was that an
  34. employee might be listed twice, because the parameter matched more than one
  35. of the fields; I fixed this by using Perl's associative arrays.  Searching
  36. for matching names was quite easy using Perl's string matching operators.
  37. One of the enhancements I was making was for it to generate both HTML and
  38. human-oriented output (so the program could be used from a CGI script on
  39. our internal web server); Perl's output handling made it relatively easy to
  40. put optional HTML output throughout the program.
  41.  
  42. I did have some performance problems with my initial version.  I found a
  43. simple optimization and the result was that the Perl version was as fast as
  44. the original C version.  On the other hand, it had no coded limits and had
  45. more features (well, to be honest, while I was at it I removed some
  46. obsolete features that were no needed).
  47. -- 
  48. Barry Margolin
  49. BBN PlaNET Corporation, Cambridge, MA
  50. barmar@bbnplanet.com
  51. Phone (617) 873-3126 - Fax (617) 873-6351
  52.